"""
Title: schedulermain.py
Author: Matthew Tanner
Project: Facultimes
This is an Oregon State University project built as a requirement for CS419. 
The project is a collaboration between Matthew Tanner, Arnold Baghomian, and
Joseph Helgeson. 

schedulermain.py is meant to provide a demonstration of the Scheduler.py API
"""

from Scheduler import Scheduler
import sys

# inputs = {"userlist": [{"name": "jess, joseph i"},
# 					{"name": "mcgreevy, sarah"},
# 					{"name": "grimm, michael j"},
# 					{"name": "mcgrath, d kevin"}],
# 		  "window": {"start": "08/05/2014 07:00", "end": "08/05/2014 17:00"}}

inputs = {"userlist": [{"name": "jess, joseph i"}],
		  "window": {"start": "08/05/2014 05:00", "end": "08/05/2014 20:00"}}

# inputs = {"userlist": [{"name": "mcgreevy, sarah"}],
# 		  "window": {"start": "08/06/2014 07:00", "end": "08/06/2014 17:00"}}

# inputs = {"userlist": [{"name": "grimm, michael j"}],
# 		  "window": {"start": "08/31/2014 05:00", "end": "09/01/2014 23:00"}}

# inputs = {"userlist": [{"name": "mcgrath, d kevin"}],
# 		  "window": {"start": "08/07/2014 07:00", "end": "08/07/2014 17:00"}}


def main():
	# Instantiate scheduler object
	s = Scheduler()

	# get list of valid users from config file
	# validUsers = s.validUsers
	# if validUsers == -1:
	# 	print s.error
	# 	sys.exit(1)
	# for user in validUsers:
	# 	print user

	# pass in all parameters in dictionary in above format
	if s.params(inputs) == -1:
		print s.error
		sys.exit(1)
	
	# send the scheduler off to get the solution
	if s.schedule() == -1:
		print s.error
		sys.exit(1)

	# print out list of times from solution
	print "times:"
	for t in s.times:

		print t[0],
		print " - ",
		print t[1]

	# print out list of attendees from solution
	print "attendees"
	for a in s.attendees:
		print a
	print

	
	# print out original parameter values
	print s.paramStartWindow,
	print " - ",
	print s.paramEndWindow

	# another attribute is allEvents, which are all the times users are BUSY within th window	
	print "Events within window:"
	for e in s.allEvents:
		if e[0] > s.paramStartWindow and e[1] < s.paramEndWindow:
			print e[0],
			print " - ",
			print e[1],
			print " ",
			print e[2]
	print
	
	# print the complete solution dictionary
	print s.solution

if __name__ == "__main__":
	main()